package ioperations;

import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        int i = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.println("归还图书......");
        System.out.print("请输入你要归还的书籍名称：");
        String name = scanner.nextLine();
        for (; i < bookList.getUseSize(); i++) {
            if(name.equals(bookList.getBooks(i).getName())){
                System.out.println(bookList.getBooks(i));
                if(bookList.getBooks(i).isState() == true){
                    bookList.getBooks(i).setState(false);
                    System.out.println("还书成功！");
                }else{
                    System.out.println(name + "未被借出！");
                }
                return ;
            }
        }
        if(i == bookList.getUseSize()){
            System.out.println("没有这本书！");
        }
    }
}
